/*****************************************************
** Author: 
** Date: 2019-11-18
*
*****************************************************/

#include "module.h"
#include "timer.h"
#include "gpio.h"
#include "pwm.h"
#include "uart.h"
#include "dnalua.h"

struct lua_module
{
	int (*open)(lua_State *l);
	int (*close)(lua_State *l);
};

static struct lua_module lua_modules[] = {
	{
		.open 	= luaopen_dnalua,
		.close 	= luaclose_dnalua,
	},
	{
		.open 	= luaopen_timer,
		.close 	= luaclose_timer,
	},
	{
		.open 	= luaopen_gpio,
		.close 	= luaclose_gpio,
	},
	{
		.open 	= luaopen_pwm,
		.close 	= luaclose_pwm,
	},
	{
		.open 	= luaopen_uart,
		.close 	= luaclose_uart,
	}
};

/**
 * @brief
 * @param  None
 * @retval None
 */
void lua_module_init(lua_State *l)
{
	struct lua_module *mdl = lua_modules;
	int i;

	for (i = 0; i < DeepOfArray(lua_modules); ++i) {
		(*mdl[i].open)(l);
	}
}

void lua_module_deinit(lua_State *l)
{
	struct lua_module *mdl = lua_modules;
	int i;

	for (i = 0; i < DeepOfArray(lua_modules); ++i) {
		(*mdl[i].close)(l);
	}
}

/* End of file */



